#!/usr/bin/env python
# encoding: utf-8
# @Time    : 2020/8/24 18:40
# @Author  : Mr. Cui
# @File    : views.py
# @Software: PyCharm
# project蓝图的视图
from flask import request

from . import mantis_bug
from ..mantis_bug.service import mantis_bug_service
from ...libs import result, const
from ...libs.validate_params import validate_params


@mantis_bug.route('/bug_by_days/<project_id>/<version_info>/<type>', methods=['get'])
def bug_by_days(project_id, version_info, type):
    """
    项目bug根据天数趋势图
    :param type: 天/小时
    :param project_id: 项目id
    :param version_info: 版本内容
    :return: json
    """
    res = mantis_bug_service.bug_by_days(project_id, version_info, type)
    return result(const.SUCCESS, const.QUERY_SUCCESS, res)


@mantis_bug.route('/bug_time_finish', methods=['post'])
@validate_params(params=["project_id", "version", "page_num", "page_per"])
def bug_time_finish():
    """
    以项目为维度，统计提出bug至解决bug时间
    :return: json
    """
    res = mantis_bug_service.bug_time_finish(request.json)
    return result(const.SUCCESS, const.QUERY_SUCCESS, res)


@mantis_bug.route('/bug_of_handler', methods=['post'])
@validate_params(params=["project", "user_id", "start_time", "end_time"])
def bug_of_handler():
    """
    人名或项目组、时间，可展示出对应人员的bug数柱状图、线上bug情况柱状图
    :return: json
    """
    res = mantis_bug_service.bug_of_handler(request.json)
    return result(const.SUCCESS, const.QUERY_SUCCESS, res)


@mantis_bug.route('/bug_of_project', methods=['post'])
@validate_params(params=["start_time", "end_time"])
def bug_of_project():
    """
    bug情况
    :return: json
    """
    print(request.data)
    res = mantis_bug_service.bug_of_project(request.json)
    return result(const.SUCCESS, const.QUERY_SUCCESS, res)


@mantis_bug.route('/bug_data_last_week', methods=['get'])
def bug_data_last_week():
    """
    上周bug严重级别分布、上周bug平台分布、上周bug类型分布、上周bug处理情况
    :return: json
    """
    res = mantis_bug_service.bug_data_last_week()
    return result(const.SUCCESS, const.QUERY_SUCCESS, res)


@mantis_bug.route('/bug_not_closed', methods=['post'])
@validate_params(params=["handler_id", "page_num", "page_per"])
def bug_not_closed():
    """
    统计对应人员bug未解决数量及列表
    一键发送邮件告知单人，一键发送邮件告知主管，一键发送邮件给项目组
    :return: json
    """
    res = mantis_bug_service.bug_not_closed(request.json)
    return result(const.SUCCESS, const.QUERY_SUCCESS, res)


@mantis_bug.route('/bug_e_mail', methods=['post'])
def bug_e_mail():
    """
    一键发送邮件告知单人，一键发送邮件告知主管，一键发送邮件给项目组,
    入参为json数组
    :return: json
    """
    mantis_bug_service.bug_e_mail(request.json)
    return result(const.SUCCESS, const.OPERATE_SUCCESS, None)
